token_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
    },
    "required": ["token"]
}

admin_damin_schema = {
    "type": "object",
    "properties": {
        "passwd": {"type": "string"},
        "ipaddr": {"type": "string",
                   "minLength": 8,
                   "maxLength": 20},
        "admin_admin": {"type": "string",
                        "minLength": 3}
    },
    "required": ["passwd", "ipaddr", "admin_admin"]
}

paging_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "page": {"type": "number",
                 "minimum": 0,
                 "exclusiveMinimum": False},
        "size": {"type": "number",
                 "minimum": 0,
                 "maximum": 1000,
                 "exclusiveMinimum": False}
    },
    "required": ["token", "page", "size"]
}

subdbid_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "sub_db_id": {"type": "string",
                      "minLength": 5,
                      "maxLength": 5},
    },
    "required": ["token", "sub_db_id"]
}

subdbid_year_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "year": {"type": "string",
                 "minLength": 4,
                 "maxLength": 4},
        "sub_db_id": {"type": "string",
                      "minLength": 5,
                      "maxLength": 5},
    },
    "required": ["token", "sub_db_id", "year"]
}

admin_user_schema = {
    "type": "object",
    "properties": {
        "username": {"type": "string",
                     "minLength": 3},
        "passwd": {"type": "string",
                   "minLength": 8,
                   "maxLength": 20},
        "ipaddr": {"type": "string",
                   "minLength": 3},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["username", "passwd", "ipaddr", "token"]
}

user_schema = {
    "type": "object",
    "properties": {
        "username": {"type": "string",
                     "minLength": 3},
        "passwd": {"type": "string",
                   "minLength": 3}
    },
    "required": ["username", "passwd"]
}

user_change_schema = {
    "type": "object",
    "properties": {
        "username": {"type": "string",
                     "minLength": 3},
        "old_pwd": {"type": "string",
                    "minLength": 3},
        "new_pwd": {"type": "string",
                    "minLength": 8,
                    "maxLength": 20},
        "retype_new_pwd": {"type": "string",
                           "minLength": 8,
                           "maxLength": 20}
    },
    "required": ["username", "old_pwd", "new_pwd", "retype_new_pwd"]
}

query_by_ids_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "ids": {"type": "array", "minItems": 1},
    },
    "required": ["token", "ids"]
}

query_onece_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "source_type": {"type": "array", "minItems": 1},
        "sub_db_id": {"type": "array", "minItems": 1},
        "pub_year_start": {"type": "string", "minLength": 1, "maxLength": 4},
        "pub_year_end": {"type": "string", "minLength": 1, "maxLength": 4},
        "where": {"type": "array", "minItems": 0, "items": {
            "type": "object",
            "properties": {
                "link": {"type": "string", "enum": ["and", "or", "not"]},
                "feild_name": {"type": "string"},
                "oparation": {"type": "string", "enum": ["equal", "like"]},
                "feild_value": {"type": "string"}
            }
        }},
    },
    "required": ["token", "source_type", "sub_db_id", "pub_year_start", "pub_year_end", "where"]

}



query_onece_page_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "source_type": {"type": "array", "minItems": 1},
        "sub_db_id": {"type": "array", "minItems": 1},
        "pub_year_start": {"type": "string", "minLength": 1, "maxLength": 4},
        "pub_year_end": {"type": "string", "minLength": 1, "maxLength": 4},
        "page": {"type": "integer", "minimum": 1, "maximum": 500},
        "size": {"type": "integer"},
        "where": {"type": "array", "minItems": 0, "items": {
            "type": "object",
            "properties": {
                "link": {"type": "string", "enum": ["and", "or", "not"]},
                "feild_name": {"type": "string"},
                "oparation": {"type": "string", "enum": ["equal", "like"]},
                "feild_value": {"type": "string"}
            }
        }},
    },
    "required": ["token", "source_type", "sub_db_id", "pub_year_start", "pub_year_end", "where","page","size"]

}

update_ref_schema = {
    "type": "object",
    "properties": {
        "sub_db_id": {"type": "string", "minLength": 5, "maxLength": 5},
        "count_submit": {"type": "integer"},
        "count_update": {"type": "integer"},
        "count_create": {"type": "integer"},
        "count_deprecated": {"type": "integer"},
        "count_delete": {"type": "integer"},
        "count_ref": {"type": "integer"},
        "token": {"type": "string", "minLength": 1},
    },
    "required": ["sub_db_id", "count_submit", "count_update", "count_create", "count_deprecated", "count_delete",
                 "count_ref", "token"]

}

update_meta_schema = {
    "type": "object",
    "properties": {
        "sub_db_id": {"type": "string", "minLength": 5, "maxLength": 5},
        "count_submit": {"type": "integer"},
        "count_update": {"type": "integer"},
        "count_create": {"type": "integer"},
        "count_deprecated": {"type": "integer"},
        "count_delete": {"type": "integer"},
        "count_meta": {"type": "integer"},
        "token": {"type": "string", "minLength": 1},
    },
    "required": ["sub_db_id", "count_submit", "count_update", "count_create", "count_deprecated", "count_delete",
                 "count_meta", "token"]

}

log_sys_schema = {
    "type": "object",
    "properties": {
        "log_json": {"type": "object"},
        "token": {"type": "string", "minLength": 1}
    },
    "required": ["log_json", "token"]
}

count_subdb_year_schema = {
    "type": "object",
    "properties": {
        "sub_db_id": {"type": "string", "minLength": 5, "maxLength": 5},
        "count_json": {"type": "object"},
        "token": {"type": "string", "minLength": 1}
    },
    "required": ["sub_db_id", "count_json", "token"]

}

es_fileds_schema = {
    "type": "object",
    "properties": {
        "advanced": {"type": "string", "enum": ["true", "false"]},
        "token": {"type": "string"}
    },
    "required": ["advanced", "token"]
}

es_lngid_schema = {
    "type": "object",
    "properties": {
        "keyid": {"type": "string", "minLength": 1},
        "token": {"type": "string"}
    },
    "required": ["keyid", "token"]
}

es_query_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "page": {"type": "integer", "minimum": 1},
        "size": {"type": "integer", "minimum": 1, "maximum": 1000},
        "source_type": {"type": "array", "minItems": 1},
        "sub_db_id": {"type": "array", "minItems": 1},
        "pub_year_start": {"type": "string", "minLength": 1, "maxLength": 4},
        "pub_year_end": {"type": "string", "minLength": 1, "maxLength": 4},
        "where": {"type": "array", "minItems": 0, "items": {
            "type": "object",
            "properties": {
                "link": {"type": "string", "enum": ["and", "or", "not"]},
                "feild_name": {"type": "string"},
                "oparation": {"type": "string", "enum": ["equal", "like"]},
                "feild_value": {"type": "string"}
            }
        }}
    },
    "required": ["token", "page", "size", "source_type", "sub_db_id", "pub_year_start", "pub_year_end"]
}

update_user_schema = {
    "type": "object",
    "properties": {
        "username": {"type": "string",
                     "minLength": 3},
        "passwd": {"type": "string",
                   "minLength": 3},
        "ipaddr": {"type": "string",
                   "minLength": 3},
        "token": {"type": "string",
                  "minLength": 3},
    }
}

move_file_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "types": {"type": "string", "enum": ["meta", "ref"]},
        "source_dir": {"type": "string", "minLength": 1},
        "explain": {"type": "string"}
    },
    "required": ["token", "types", "source_dir"]
}

validation_filename_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "types": {"type": "string", "enum": ["meta", "ref"]},
        "filenames": {"type": "array", "minItems": 1}
    },
    "required": ["token", "types", "filenames"]
}

file_get_log_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "log_type": {"type": "integer", "enum": [0, 1, 2, 3]},
        "page": {"type": "integer", "minimum": 1},
        "size": {"type": "integer", "minimum": 10, "maximum": 100}
    },
    "required": ["token", "log_type", "page", "size"]
}

get_dir_files_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "source_dir": {"type": "string", "minLength": 1},
    },
    "required": ["token", "source_dir"]
}

extract_rule_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "rule_type": {"type": "integer", "enum": [0, 1]},
        "rule": {"type": "array", "minItems": 1, "items": {
            "type": "object",
            "properties": {
                "sub_db_id": {"type": "string", "minLength": 5, "maxLength": 5},
                "type": {"type": "string", "enum": ["meta", "ref"]},
                "pub_year": {"type": "string"},
                "field": {"type": "object"}
            }
        },
                 "required": ["token", "rule"]
                 }

    }
}

get_once_rule_status_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "oozie_id": {"type": "string", "minLength": 1},
        "required": ["token", "oozie_id"]
    }
}

get_sub_db_field_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "sub_db_id": {"type": "string",
                      "minLength": 5,
                      "maxLength": 5},
    },
    "required": ["token", "sub_db_id"]
}

oozie_log_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "username": {"type": "string", "minLength": 1},
        "ip": {"type": "string", "minLength": 1},
        "ruleid": {"type": "string", "minLength": 1},
        "file_type": {"type": "integer", "enum": [0, 1, 2]},
        "log_json": {"type": "object", "minItems": 1}
    },
    "required": ["token", "username", "ip", "ruleid", "file_type", "log_json"]
}

oozie_stat_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "ruleid": {"type": "integer", "minLength": 1},
        "stat": {"type": "string", "enum": ["SUBMITTED", "RUNNING", "FINISHED", "FAILED", "KILLED"]},
    },
    "required": ["token", "ruleid", "stat"]
}

get_rule_list_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "rule_type": {"type": "integer", "enum": [0, 1, 2]},
        "page": {"type": "integer", "minimum": 1},
        "size": {"type": "integer", "minimum": 10, "maximum": 100}
    },
    "required": ["token", "rule_type", "page", "size"]
}

get_rule_log_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "rule_id": {"type": "integer"},
    },
    "required": ["token", "rule_id"]
}

get_file_list_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "ruleid": {"type": "integer", "minLength": 1},
    },
    "required": ["token", "ruleid"]
}

down_file_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string", "minLength": 1},
        "ruleid": {"type": "integer", "minLength": 1},
        "filename": {"type": "string", "minLength": 1},
    },
    "required": ["token", "ruleid", "filename"]
}

field_schema = {
    "type": "object",
    "properties": {
        "field_name": {"type": "string",
                       "minLength": 1},
        "field_remarks": {"type": "string"},
        "field_type": {"type": "string",
                       "minLength": 1},
        "user": {"type": "string"},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["field_name", "field_remarks", "field_type", "token"]
}

update_field_schema = {
    "type": "object",
    "properties": {
        "old_field_name": {"type": "string",
                           "minLength": 1},
        "field_name": {"type": "string",
                       "minLength": 1},
        "field_remarks": {"type": "string"},
        "field_type": {"type": "string",
                       "minLength": 1},
        "user": {"type": "string"},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["old_field_name", "field_name", "field_remarks", "field_type", "token"]
}

delete_field_schema = {
    "type": "object",
    "properties": {
        "field_name": {"type": "string",
                       "minLength": 1},
        "user": {"type": "string"},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["field_name", "token"]
}

relation_schema = {
    "type": "object",
    "properties": {
        "type_id": {"type": "integer",
                    "minLength": 1},
        "field_id": {"type": "integer"},
        "index_type": {"type": "string"},
        "field_sample": {"type": "string"},
        "order": {"type": "integer"},
        "user": {"type": "string"},
        "field_remarks": {"type": "string"},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["type_id", "field_id", "index_type", "field_sample", "order", "field_remarks", "token"]
}

select_relation_schema = {
    "type": "object",
    "properties": {
        "type_id": {"type": "string",
                    "minLength": 1},
        "field_id": {"type": "string",
                     "minLength": 1},
        "token": {"type": "string"},
    },
    "required": ["type_id", "field_id", "token"]
}

update_relation_schema = {
    "type": "object",
    "properties": {
        "relation_id": {"type": "integer"},
        "index_type": {"type": "string"},
        "field_sample": {"type": "string"},
        "order": {"type": "integer"},
        "user": {"type": "string"},
        "field_remarks": {"type": "string"},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["relation_id", "index_type", "field_sample", "order", "field_remarks", "token"]
}

delete_relation_schema = {
    "type": "object",
    "properties": {
        "user": {"type": "string"},
        "token": {"type": "string",
                  "minLength": 3}
    },
    "required": ["relation_id", "token"]
}

relation_order_schema = {
    "type": "object",
    "properties": {
        "token": {"type": "string"},
        "update_order": {
            "type": "array",
            "minItems": 0,
            "items": {
                "type": "object",
                "properties": {
                    "relation_id": {"type": "integer"},
                    "order": {"type": "integer"},
                }
            }
        }
    },
    "required": ["token"]

}

select_field_not_in_relation_schema = {
    "type": "object",
    "properties": {
        "type_id": {"type": "integer"},
        "token": {"type": "string"},
    },
    "required": ["type_id", "token"]
}
